<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
/** 
* Menu Class 
* 
* Class to determine menu, such as when member login disable login and 
* register button
*
* @category	Libraries
* @subpackage Custom Libraries
* @author Ari Oaks
*/

class Mymenu{

	var $CI;
	var $menus;
	//var $menus['menu_main'] = array();
	
	function Mymenu()
	{
		$this->CI =& get_instance();
	}
	
	function menu_header()
	{
		$segment = str_replace("_html", "", $this->CI->uri->segment(1, 0));
		
		if($segment == 'halaman'):
			$segment = str_replace("_html", "", $this->CI->uri->segment(3, 0));
		endif;
		
		$menus = $this->CI->Menu_model->get_menus(1)->result_array();
		$menu = '<ul>';
		foreach($menus as $item):

			$slug = $item['slug'];
			$submenus = $this->CI->Menu_model->get_menus($item['id'])->result_array();
			
			if($submenus):
			
				$menu .= '<li class="sub '.$active.'">'.strtoupper($item['title']);
				$menu .= '<ul class="submenu">';	
				
					foreach($submenus as $sub):
						$slug = $sub['slug'];
						$menu .= '<li class="'.$active.'"><a href="'.site_url($slug).'">'.strtoupper($sub['title']).'</a></li>';
					endforeach;
					
				$menu .=  '</ul></li>';
				
			else:
			
				if($slug==''):
					$active = (!$segment) ? 'active' : '';
					$menu .= 	'<li class="'.$active.'"><a href="'.site_url($slug).'">'.strtoupper($item['title']).'</a></li>';
				else:
					$active = ($segment && $segment==$item['slug']) ? 'active' : '';
					$menu .= 	'<li class="'.$active.'"><a href="'.site_url($slug).'">'.strtoupper($item['title']).'</a></li>';
				endif;
				
			endif;
				
		endforeach;
		$menu .= 	'</ul>';
		return $menu;
	}
	
	function menu_footer()
	{
		
		$segment = str_replace("_html", "", $this->CI->uri->segment(1, 0));
		
		if($segment == 'halaman'):
			$segment = str_replace("_html", "", $this->CI->uri->segment(3, 0));
		endif;
		
		$menus = $this->CI->Menu_model->get_menus(2)->result_array();
		$menu = '';
		foreach($menus as $item):

				$slug = $item['slug'];
			
				if($slug==''):
					$active = (!$segment) ? 'active' : '';
					$menu .= 	'<a class="'.$active.'" href="'.site_url($slug).'">'.ucfirst($item['title']).'</a> / ';
				else:
					$active = ($segment && $segment==$item['slug']) ? 'active' : '';
					$menu .= 	'<a class="'.$active.'" href="'.site_url($slug).'">'.ucfirst($item['title']).'</a> / ';
				endif;
				
		endforeach;
		$menu .= 	'';
		return $menu;
	}
	
}

/* End of file Mymenu.php */ 
/* Location: ./system/application/libraries/Mymenu.php */ 